package org.liziyi.pss.config;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
 * @author liziyi
 */
public class Config {
    public static int mainGUIWidth;
    public static int mainGUIHeight;
    public static int memoryTotalSize;
    public static int memorySysSize;
    public static int cpuCore;
    public static int timeSlice;
    public static int timeSliceNumMin;
    public static int timeSliceNumMax;
    public static int priorityMin;
    public static int priorityMax;
    public static int memoryMin;
    public static int memoryMax;
    public static double syncProcessScale;
    public static List<Integer> syncProcessGroupSize;
    public static void loadConfig() {
        // 读取屏幕配置
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Rectangle bounds = ge.getDefaultScreenDevice().getDefaultConfiguration().getBounds();
        int screenWidth = bounds.width;
        int screenHeight = bounds.height;
        // 读取配置文件
        try{
            Properties properties=new Properties();
            properties.load(Config.class.getClassLoader().getResourceAsStream("pss.properties"));
            mainGUIWidth=(int)(screenWidth*Double.parseDouble(properties.getProperty("pss.mainGUI.scale.width")));
            mainGUIHeight=(int)(screenHeight*Double.parseDouble(properties.getProperty("pss.mainGUI.scale.height")));
            memoryTotalSize=Integer.parseInt(properties.getProperty("pss.memory.size.total"));
            memorySysSize=Integer.parseInt(properties.getProperty("pss.memory.size.sys"));
            cpuCore=Integer.parseInt(properties.getProperty("pss.cpu.core"));
            timeSlice=Integer.parseInt(properties.getProperty("pss.cpu.timeSlice.time"));
            timeSliceNumMin=Integer.parseInt(properties.getProperty("pss.process.timeSlice.numMin","1"));
            timeSliceNumMax=Integer.parseInt(properties.getProperty("pss.process.timeSlice.numMax","15"));
            priorityMin=Integer.parseInt(properties.getProperty("pss.process.priority.min","1"));
            priorityMax=Integer.parseInt(properties.getProperty("pss.process.priority.max","10"));
            memoryMin=Integer.parseInt(properties.getProperty("pss.process.memory.min","1"));
            memoryMax=Integer.parseInt(properties.getProperty("pss.process.memory.max","10"));
            syncProcessScale=Double.parseDouble(properties.getProperty("pss.process.sync.scale","0.1"));
            syncProcessGroupSize=new ArrayList<>();
            String v;
            for(int i=0;(v=properties.getProperty(String.format("pss.process.sync.group.size[%d]",i)))!=null;i++){
                syncProcessGroupSize.add(Integer.parseInt(v));
            }
            if(syncProcessGroupSize.isEmpty()){
                syncProcessGroupSize.add(2);
                syncProcessGroupSize.add(3);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
